<%--
  Created by IntelliJ IDEA.
  User: XBB
  Date: 2021/1/29
  Time: 19:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html class="loginHtml">
<head>
    <meta charset="utf-8">
    <title>登录--房屋租赁</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="${pageContext.request.contextPath}/static/layuicms/favicon.ico">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuicms/css/public.css" media="all" />
</head>
<body class="loginBody">
<form class="layui-form">
    <div class="login_face"><img src="${pageContext.request.contextPath}/static/layuicms/images/face.jpg" class="userAvatar"></div>
    <div class="layui-form-item input-item">
        <label for="userName">用户名</label>
        <input type="text" placeholder="请输入用户名" autocomplete="off" id="userName" name="adminName" class="layui-input" lay-verify="required">
    </div>
    <div class="layui-form-item input-item">
        <label for="password">密码</label>
        <input type="password" placeholder="请输入密码" autocomplete="off" id="password" name="adminPwd" class="layui-input" lay-verify="required">
    </div>
    <div class="layui-form-item input-item" id="imgCode" style="width: 45%;float: left">
        <label for="code">验证码</label>
        <input type="text" placeholder="请输入验证码" autocomplete="off" id="code" name="code" class="layui-input" lay-verify="required"/>
        <%--<img src="${pageContext.request.contextPath}/static/layuicms/images/code.jpg">--%>

    </div>&emsp;
    <img id="yzmImg" src="${pageContext.request.contextPath}/autoYzm" title="点击刷新" onclick="yzmFlush(this)"/>
    <div class="layui-form-item">
        <button class="layui-btn layui-block" lay-filter="login" lay-submit>登录</button>
    </div>
    <div class="layui-form-item layui-row">
        <a href="javascript:;" class="seraph icon-qq layui-col-xs4 layui-col-sm4 layui-col-md4 layui-col-lg4"></a>
        <a href="javascript:;" class="seraph icon-wechat layui-col-xs4 layui-col-sm4 layui-col-md4 layui-col-lg4"></a>
        <a href="javascript:;" class="seraph icon-sina layui-col-xs4 layui-col-sm4 layui-col-md4 layui-col-lg4"></a>
    </div>
</form>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layuicms/layui/layui.js"></script>
<script >

    layui.use(['form','layer','jquery'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

        $(".loginBody .seraph").click(function(){
            layer.msg("这只是做个样式，至于功能，你见过哪个后台能这样登录的？还是老老实实的找管理员去注册吧",{
                time:5000
            });
        })

        //登录按钮
        form.on("submit(login)",function(data){
            // 文本输入框全部检查一次  有没有值



            $(this).text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
            setTimeout(function(){
                // window.location.href = "/layuicms2.0";

                $.post("${pageContext.request.contextPath}/login",data.field,function (r) {
                    if(r == "1"){
                        // 找到了 ，跳转其他页面
                        window.location.href = "${pageContext.request.contextPath}/indexInit";
                    }else{
                        layer.msg("您输入的账号或密码错误", {
                            offset: '300px'
                            ,icon: 2
                            ,time: 1000
                        },function () {
                            window.location.href = "${pageContext.request.contextPath}/loginInit"
                        });

                    }
                })


            },1000);
            return false;
        })

        //表单输入效果
        $(".loginBody .input-item").click(function(e){
            e.stopPropagation();
            $(this).addClass("layui-input-focus").find(".layui-input").focus();
        })
        $(".loginBody .layui-form-item .layui-input").focus(function(){
            $(this).parent().addClass("layui-input-focus");
        })
        $(".loginBody .layui-form-item .layui-input").blur(function(){
            $(this).parent().removeClass("layui-input-focus");
            if($(this).val() != ''){
                $(this).parent().addClass("layui-input-active");
            }else{
                $(this).parent().removeClass("layui-input-active");
            }
        })

        // 给验证码添加光标移出事件
        $(document).on('blur','#code',function(){
            // 获取输入框的值
            var code = $("#code").val()
            if(code == ""){
                layer.msg("验证码不能为空", {
                    offset: '300px'
                    ,icon: 2
                    ,time: 1000
                });
                // 刷新验证码
                $("#yzmImg").attr("src","${pageContext.request.contextPath}/autoYzm?d="+new Date())
                return;
            }

            $.post("${pageContext.request.contextPath}/chkYzm",{"yzm":code},function (r) {
                if(r == "0"){

                }else{
                    layer.msg("验证码输入错误", {
                        offset: '300px'
                        ,icon: 2
                        ,time: 1000
                    });

                    // 刷新验证码
                    $("#yzmImg").attr("src","${pageContext.request.contextPath}/autoYzm?d="+new Date())
                }
            })

        });



    })

    // 给刷新验证码添加方法
    function yzmFlush(t) {
        t.src = "${pageContext.request.contextPath}/autoYzm?d="+new Date()
    }



</script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layuicms/js/cache.js"></script>
</body>
</html>